package com.m.man.rigth.loginRight;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

//@Component  //implements HandlerInterceptor
//public class LoginRigth  {

//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
//
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
//
//    }
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
//
//        HttpSession session = request.getSession(true);
//        Object userName = session.getAttribute("userName");
//
//        if(null != userName){ //  已经登录
//            return true;
//        }else {  //  未登录
//            System.out.println("request.getContextPath()=="+request.getContextPath()+"<<");
//            response.sendRedirect(request.getContextPath()+"/index.html");
//            return false;
//        }
//        // 普通路径  放行
////        if ( "/yanzheng".equals(request.getRequestURI()) || "/login".equals(request.getRequestURI()) ){
////            return true;
////        }
////        // 权限路径  拦截
////        Object object = request.getSession().getAttribute("user");
////        if ( null == object ){
////            response.sendRedirect("/login");
////            return false;
////        }
////        return false;
//    }
//}
